package com.example.controller;


import com.example.bo.TestSzxBO;
import com.example.bo.UnifiedResponse;
import com.example.mapper.ds1.UserMapper1;
import com.example.mapper.ds2.UserMapper2;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/sql")
@Slf4j
public class SqlTest {
    @Autowired
    private UserMapper1 userMapper1;
    @Autowired
    //@Resource
    private UserMapper2 userMapper2;

    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

    @ResponseBody
    @RequestMapping(value = "/mysql",method = RequestMethod.GET)
    public Object mysql(){
        List<TestSzxBO> testSzxBOList = userMapper1.getAll();
        log.info("result:"+testSzxBOList);
        UnifiedResponse unifiedResponse = new UnifiedResponse();
        unifiedResponse.setData(testSzxBOList);
        return unifiedResponse;
    }

    @ResponseBody
    @RequestMapping(value = "/gaussdb",method = RequestMethod.GET)
    public Object gaussdb(){
        List<TestSzxBO> testSzxBOList = userMapper2.getAll();
        log.info("result:"+testSzxBOList);
        UnifiedResponse unifiedResponse = new UnifiedResponse();
        unifiedResponse.setData(testSzxBOList);
        return unifiedResponse;
    }
    @ResponseBody
    @RequestMapping(value = "/select",method = RequestMethod.GET)
    public Object select(){
        String s="{\"data\":[{\"id\":\"1\",\"name\":\"zhangsan\"},{\"id\":\"2\",\"name\":null}],\"message\":\"ok\"}";
        return s;
    }

    @ResponseBody
    @RequestMapping(value = "/insert",method = RequestMethod.GET)
    public Object insert(){
        String s="{\"data\":null,\"message\":\"ok\"}";
        return s;
    }

    @ResponseBody
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public Object delete(){
        String s="{\"data\":null,\"message\":\"ok\"}";
        return s;
    }

    @ResponseBody
    @RequestMapping(value = "/update",method = RequestMethod.GET)
    public Object update(){
        String s="{\"data\":null,\"message\":\"ok\"}";
        return s;
    }

}
